﻿<UserControl x:Class="CodeAbility.MonitorAndCommand.WpfMonitor.UserControls.DeviceDataUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:CodeAbility.MonitorAndCommand.WpfMonitor.Converters"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <UserControl.Resources>
        <converters:BooleanToOpacityConverter x:Key="BooleanToOpacity"></converters:BooleanToOpacityConverter>
        <Style x:Key="RectangleStyle" TargetType="Rectangle">
            <Setter Property="Margin" Value="2"></Setter>
            <Setter Property="Width" Value="16"></Setter>
            <Setter Property="Height" Value="16"></Setter>
            <Setter Property="StrokeThickness" Value="5"></Setter>
        </Style>
        <Style x:Key="DeviceStyle" TargetType="TextBlock">
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Margin" Value="2"/>
            <Setter Property="FontSize" Value="22"/>
        </Style>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Column="0" Text="{Binding Name}" Style="{StaticResource DeviceStyle}"></TextBlock>

        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="25"/>
                <RowDefinition Height="25"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="40"/>
                <ColumnDefinition Width="50"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Rectangle Grid.Row="0" Grid.Column="0"
                       Style="{StaticResource RectangleStyle}"
                       Fill="Green" 
                       Opacity="{Binding MessageReceived, Converter={StaticResource BooleanToOpacity}, FallbackValue=0.25}">
            </Rectangle>

            <Rectangle Grid.Row="1" Grid.Column="0"
                       Style="{StaticResource RectangleStyle}"
                       Fill="Blue" 
                       Opacity="{Binding MessageSent, Converter={StaticResource BooleanToOpacity}, FallbackValue=0.25}"/>

        </Grid>

    </Grid>
</UserControl>
